﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;

namespace DAL.ConexionBD
{
    public class ConexionSQL
    {
        private SqlConnection cnn = null;
        private static ConexionSQL instanciaUnica = null;
        private String cadenaConexion = "Data Source =.; Initial Catalog = Kardex; integrated Security = true ";
        //private string cadenaConexion = ConfigurationManager.ConnectionStrings["ProyectoKardexConnectionString"].ConnectionString;

        public static ConexionSQL getInstancia()
        {
            if (instanciaUnica == null)
            {
                instanciaUnica = new ConexionSQL();
            }
            return instanciaUnica;
        }

        public IDbConnection getConexion()
        {

            try
            {

                cnn = new SqlConnection(cadenaConexion);

            }
            catch (SqlException ex)
            {
                throw new Exception("Error SQL: " + ex.Message);
            }
            catch (Exception e)
            {
                throw new Exception("Error : " + e.Message);
            }

            return cnn;
        }
    }
}
